const API_URL = 'http://localhost:3000'


//使用myAjax方法，必须要先引入jquery
function myAjax(option = {}) {
    let { url = '', method = 'get', data = {}, headers = {} } = option
    /*
       let { url = '', method = 'get', data = {} } = {
            url: '/api/courseinfo'
        }
    */
    return new Promise((resolve, reject) => {
        $.ajax({
            url: API_URL + url, //   http://localhost:3000/api/courseinfo
            method,
            data,
            headers: {
                //ajax中的headers就是传递请求头参数
                authorization: localStorage.getItem('token')
            },
            success(result) {
                // console.log(result, '我是结果3')
                resolve({ err: null, result })
                    // console.log(result, API_URL + url)
            },
            error(err) {
                resolve({ err })
            }
        })
    })
}

//demo

// async function myDemo(){
//     let res = await myAjax({
//         url,
//         data,
//         method,
//     })
// }